import org.junit.Test;
import redis.clients.jedis.Jedis;

import java.util.Scanner;

public class TestRedis {
    private static final String host_windows ="127.0.0.1";
    private static final String host_linux ="192.168.50.128";

    private static final String pwd ="redis@WSX!QAZ1234XXX";
    private static int port =6379; //linx端口号默认为6379
    //@Test
    //public  void testLinkWindows(){
    public static void main(String[] args) {
        //选择server
        Scanner input =new Scanner(System.in);
        System.out.println("请选择:1: 连接windows 2:连接linxu");
        int choice = input.nextInt();
        String server = choice==1?host_windows:host_linux;
        //实例化Jedis
        Jedis jedis = new Jedis(server,port);
        //设置连接密码
        jedis.auth(pwd);
        //写入
        jedis.set("str","v-str");
        System.out.println("写入成功");

        //读取 如果报错的话,试试pom文件的jredis的版本调低一点
        String uname = jedis.get("str");
        System.out.println("读取redis中的userName 为: "+uname);
    }

}
